{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from os import popen\n",
    "from os import system\n",
    "from qrcode import make\n",
    "from time import sleep"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_sn():\n",
    "    sn = ''\n",
    "    a = popen('wmic bios get serialnumber').read()\n",
    "    for line in a.splitlines():\n",
    "        if line:\n",
    "            if 'SerialNumbe' in line:\n",
    "                pass\n",
    "            else:\n",
    "                print('\\tSerialNumbe is ',line)\n",
    "                sn = line.strip()\n",
    "    if sn == '':\n",
    "        print('\\t***************** \\033[1;32;43m test \\033[0m!错误！找不到SN....我也不知道怎么解决\\033[0m!*****************')\n",
    "    return sn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def get_mac():\n",
    "    mac = ''\n",
    "    a = popen('ipconfig /all').read().splitlines()\n",
    "    n = 0\n",
    "    for i in a:\n",
    "        n = n + 1\n",
    "        if 'Bluetooth' in i:\n",
    "            print('\\t',a[n-1])\n",
    "            print('\\t',a[n])\n",
    "            mac = a[n]\n",
    "    start = mac.find(':') + 1\n",
    "    if mac == '':\n",
    "        print('\\t*****************\\033[1;32;43m test \\033[0m!错误！程序太垃圾，请自己在powershell输入ipconfig /all ，然后自己找\\033[0m!*****************')\n",
    "    else:\n",
    "        mac = mac[start:].strip().replace('-','')\n",
    "    return mac"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_qr(code):\n",
    "    img = make(code)\n",
    "    img.save('test.png')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def make_qr():\n",
    "    system('cls')\n",
    "    print('####################################### 一碰传标签二维码生成器 ###############################################')\n",
    "    print('随便做的，出错不负责。可以问我，不一定修复\\n')\n",
    "    print('coolapk: 花不语笑人痴')\n",
    "    sn = get_sn()\n",
    "    mac = get_mac()\n",
    "    code = \"SN=\" + sn + \"|MAC=\" + mac +\"|MODELID=00000506\"\n",
    "    get_qr(code)\n",
    "    dir = popen('echo %cd%').read().replace('\\n', '').replace('\\r', '') + \"\\\\test.png\"\n",
    "    print('一碰传助手来自https://github.com/webviewisbad/-apk ，请大家有空帮大佬点小星星')\n",
    "    print('运行结束，获得的代码为:\\n',code,'\\n二维码保存路径： ',dir)\n",
    "    print('若SN中含有/ ,你的电脑不支持。没设备我也不知道该怎么搞。若你的SN是“Not Applicable”，也是用不了')\n",
    "    system('test.png')\n",
    "    print('####################################### 一碰传标签二维码生成器 ###############################################\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def disable_apps():\n",
    "    system('cls')\n",
    "    #检测是否有adb程序：\n",
    "    check = 0\n",
    "    while check < 2:\n",
    "        check = 0\n",
    "        adb = system('adb.exe devices')\n",
    "        if adb == 0:\n",
    "            check = check + 1\n",
    "        else:\n",
    "            print('找不到电脑adb.exe，请确保adb.exe以及相关dll文件在同一目录')\n",
    "            input('按回车键重试')\n",
    "            \n",
    "        devices = popen('adb.exe devices').read().splitlines()\n",
    "        if devices[1] == '':\n",
    "            print('找不到ADB设备，请确认是否启动手机ADB调试')\n",
    "            input('按回车键重试')\n",
    "        else:\n",
    "            print(\"已连接\",devices[1])\n",
    "            check = check + 1\n",
    "            \n",
    "    \n",
    "    #\n",
    "    \n",
    "    clean = \"adb shell pm clear \"\n",
    "    diss = \"adb shell pm disable-user \"\n",
    "    app1 = \"com.huawei.android.instantshare\"\n",
    "    app2 = \"com.huawei.pcassistant\"\n",
    "    app3 = \"com.huawei.iconnect\"\n",
    "    app4 = \"com.android.nfc\"\n",
    "    app5 = \"com.huawei.android.internal.app\"\n",
    "    \n",
    "    #禁用程序\n",
    "    print(popen(diss + app1).read())\n",
    "    print(popen(diss + app2).read())\n",
    "    print(popen(diss + app3).read())\n",
    "    print(popen(diss + app4).read())\n",
    "    print(popen(diss + app5).read())\n",
    "    \n",
    "\n",
    "    print('清理app存储')\n",
    "    c1 = popen(clean + app1).read()\n",
    "    c2 = popen(clean + app2).read()\n",
    "    c3 = popen(clean + app3).read()\n",
    "    c4 = popen(clean + app4).read()\n",
    "    c5 = popen(clean + app5).read()\n",
    "    \n",
    "    print('wipe ',app1,' data ',c1)\n",
    "    print('wipe ',app2,' data ',c2)\n",
    "    print('wipe ',app3,' data ',c3)\n",
    "    print('wipe ',app4,' data ',c4)\n",
    "    print('wipe ',app5,' data ',c5)\n",
    "    \n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def enable_apps():\n",
    "    #检测是否有adb程序：\n",
    "    check = 0\n",
    "    while check < 2:\n",
    "        check = 0\n",
    "        adb = system('adb.exe devices')\n",
    "        if adb == 0:\n",
    "            check = check + 1\n",
    "        else:\n",
    "            print('找不到电脑adb.exe，请确保adb.exe以及相关dll文件在同一目录')\n",
    "            input('按回车键重试')\n",
    "            \n",
    "        devices = popen('adb.exe devices').read().splitlines()\n",
    "        if devices[1] == '':\n",
    "            print('找不到ADB设备，请确认是否启动手机ADB调试')\n",
    "            input('按回车键重试')\n",
    "        else:\n",
    "            print(\"已连接\",devices[1])\n",
    "            check = check + 1\n",
    "            \n",
    "    en = 'adb shell pm enable '\n",
    "    app1 = \"com.huawei.android.instantshare\"\n",
    "    app2 = \"com.huawei.pcassistant\"\n",
    "    app3 = \"com.huawei.iconnect\"\n",
    "\n",
    "    app5 = \"com.huawei.android.internal.app\"\n",
    "    print(popen(en + app1).read())\n",
    "    print(popen(en + app2).read())\n",
    "    print(popen(en + app3).read())\n",
    "\n",
    "    print(popen(en + app5).read())\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def touchshare():\n",
    "    if input('安装一碰传助手？ y/n ') == 'y':\n",
    "        #检测是否有adb程序：\n",
    "        check = 0\n",
    "        while check < 2:\n",
    "            check = 0\n",
    "            adb = system('adb.exe devices')\n",
    "            if adb == 0:\n",
    "                check = check + 1\n",
    "            else:\n",
    "                print('找不到电脑adb.exe，请确保adb.exe以及相关dll文件在同一目录')\n",
    "                input('按回车键重试')\n",
    "                \n",
    "            devices = popen('adb.exe devices').read().splitlines()\n",
    "            if devices[1] == '':\n",
    "                print('找不到ADB设备，请确认是否启动手机ADB调试')\n",
    "                input('按回车键重试')\n",
    "            else:\n",
    "                print(\"已连接\",devices[1])\n",
    "                check = check + 1\n",
    "        \n",
    "        system('adb install touchshare.apk')\n",
    "    else:\n",
    "        pass\n",
    "    \n",
    "        \n",
    "    system(\"adb.exe shell am start -n com.huawei.touchshare/.ui.MainActivity\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def nfctool():\n",
    "    if input('安装NFC Tool 以擦除标签？ y/n ') == 'y':\n",
    "        #检测是否有adb程序：\n",
    "        check = 0\n",
    "        while check < 2:\n",
    "            check = 0\n",
    "            adb = system('adb.exe devices')\n",
    "            if adb == 0:\n",
    "                check = check + 1\n",
    "            else:\n",
    "                print('找不到电脑adb.exe，请确保adb.exe以及相关dll文件在同一目录')\n",
    "                input('按回车键重试')\n",
    "                \n",
    "            devices = popen('adb.exe devices').read().splitlines()\n",
    "            if devices[1] == '':\n",
    "                print('找不到ADB设备，请确认是否启动手机ADB调试')\n",
    "                input('按回车键重试')\n",
    "            else:\n",
    "                print(\"已连接\",devices[1])\n",
    "                check = check + 1\n",
    "        \n",
    "        system('adb install nfctool.apk')\n",
    "    else:\n",
    "        pass\n",
    "    \n",
    "    system(\"adb.exe shell am start -n com.wakdev.nfctools.pro/com.wakdev.nfctools.pro.MainActivityPro\")\n",
    "    \n",
    "    print(popen('adb shell pm enable com.android.nfc').read())\n",
    "    print('请手动开启NFC')\n",
    "    print('请在NFC Tools应用中选择 “其它”-“删除标签”')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "def main_menu():\n",
    "    system('cls')\n",
    "    print('####################################### 一碰传标签二维码生成器 ###############################################')\n",
    "    print('coolapk:花不语笑人痴')\n",
    "    print('免费软件，不收费。\\n 本程序源代码请访问 https://github.com/Masterchiefm/Thirdparty-huawei-Share-OneHop ')\n",
    "    print('一碰传助手来自 https://github.com/webviewisbad/-apk')\n",
    "    print('有条件的同学帮我GitHub点个小星星')\n",
    "    \n",
    "    print('\\n\\t 1.制作标签')\n",
    "    print('\\t 2.擦除标签以及清除手机标签记录')\n",
    "    print('\\t 3.一碰传失效修复')\n",
    "    print('\\t 4.清除手机标签记录（没调试。用不了就直接运行2也可以达到一样效果）')\n",
    "    print('####################################### 一碰传标签二维码生成器 ###############################################')\n",
    "    opt = int(input('\\n\\t输入选项: '))\n",
    "    if opt == 1:\n",
    "        touchshare()\n",
    "        make_qr()\n",
    "    elif opt == 3:\n",
    "        print('你在擦除标签后，一碰传用不了，一直显示“发现标签”而不启动一碰传功能，那是因为你擦除完标签就拔掉数据线了，程序还没走完呢！')\n",
    "        print('不过别急，这里帮你补完剩下的流程。')\n",
    "        input('手机插上电脑，回车继续...')\n",
    "        enable_apps()\n",
    "        system('adb reboot')\n",
    "        input('重启完成就按回车，别拔数据线，后面还有设置...')\n",
    "        system('adb shell pm enable com.android.nfc')\n",
    "        enable_apps()\n",
    "        print('自己打开NFC')\n",
    "        print('现在你可以拔掉数据线了')\n",
    "    elif opt == 4:\n",
    "        disable_apps()\n",
    "        system('adb shell pm enable com.android.nfc')\n",
    "        enable_apps()\n",
    "    elif opt == 2:\n",
    "        print('\\t风险告知: \\n\\t 1.你的手机将会被我重启 \\n\\t 2.本程序会冻结多个程序  \\n\\t 3.多次冻结会有一定几率导致程序BUG而需要手机恢复出厂(目前没遇到过)')\n",
    "        input('回车继续...')\n",
    "        disable_apps()\n",
    "        print('不要慌，是我在帮你重启手机')\n",
    "        system('adb reboot')\n",
    "        input('重启完成就按回车，别拔数据线，后面还有设置...')\n",
    "        disable_apps()\n",
    "        \n",
    "        nfctool()\n",
    "        \n",
    "        input('标签删除了吗？删除了就回车继续吧，别拔数据线，后面还有设置...')\n",
    "        if input('要启动制作新标签的进程吗？ y/n ') == 'y':\n",
    "            touchshare()\n",
    "            make_qr()\n",
    "        else:\n",
    "            pass\n",
    "        \n",
    "        \n",
    "        input('搞完了就回车，别拔数据线，后面还有设置...')\n",
    "        enable_apps()\n",
    "        system('adb reboot')\n",
    "        input('重启完成就按回车，别拔数据线，后面还有设置...')\n",
    "        \n",
    "        system('adb shell pm enable com.android.nfc')\n",
    "        enable_apps()\n",
    "        print('自己打开NFC')\n",
    "        print('现在你可以拔掉数据线了')\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "####################################### 一碰传标签二维码生成器 ###############################################\n",
      "coolapk:花不语笑人痴\n",
      "免费软件，不收费。\n",
      " 本程序源代码请访问 https://github.com/Masterchiefm/Thirdparty-huawei-Share-OneHop \n",
      "一碰传助手来自 https://github.com/webviewisbad/-apk\n",
      "有条件的同学帮我GitHub点个小星星\n",
      "\n",
      "\t 1.制作标签\n",
      "\t 2.擦除标签以及清除手机标签记录\n",
      "####################################### 一碰传标签二维码生成器 ###############################################\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "\n",
      "\t输入选项:  2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t风险告知: \n",
      "\t 1.你的手机将会被我重启 \n",
      "\t 2.本程序会冻结多个程序  \n",
      "\t 3.多次冻结会有一定几率导致程序BUG而需要手机恢复出厂(目前没遇到过)\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "回车继续... \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "已连接 HJS5T19425004323\tdevice\n",
      "Package com.huawei.android.instantshare new state: disabled-user\n",
      "\n",
      "Package com.huawei.pcassistant new state: disabled-user\n",
      "\n",
      "Package com.huawei.iconnect new state: disabled-user\n",
      "\n",
      "Package com.android.nfc new state: disabled-user\n",
      "\n",
      "Package com.huawei.android.internal.app new state: disabled-user\n",
      "\n",
      "清理app存储\n",
      "wipe  com.huawei.android.instantshare  data  Success\n",
      "\n",
      "wipe  com.huawei.pcassistant  data  Success\n",
      "\n",
      "wipe  com.huawei.iconnect  data  Success\n",
      "\n",
      "wipe  com.android.nfc  data  Success\n",
      "\n",
      "wipe  com.huawei.android.internal.app  data  Success\n",
      "\n",
      "不要慌，是我在帮你重启手机\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "重启完成就按回车... \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "找不到ADB设备，请确认是否启动手机ADB调试\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "按回车键重试 \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "已连接 HJS5T19425004323\tdevice\n",
      "Package com.huawei.android.instantshare new state: disabled-user\n",
      "\n",
      "Package com.huawei.pcassistant new state: disabled-user\n",
      "\n",
      "Package com.huawei.iconnect new state: disabled-user\n",
      "\n",
      "Package com.android.nfc new state: disabled-user\n",
      "\n",
      "Package com.huawei.android.internal.app new state: disabled-user\n",
      "\n",
      "清理app存储\n",
      "wipe  com.huawei.android.instantshare  data  Success\n",
      "\n",
      "wipe  com.huawei.pcassistant  data  Success\n",
      "\n",
      "wipe  com.huawei.iconnect  data  Success\n",
      "\n",
      "wipe  com.android.nfc  data  Success\n",
      "\n",
      "wipe  com.huawei.android.internal.app  data  Success\n",
      "\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "安装NFC Tool 以擦除标签？ y/n  n\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Package com.android.nfc new state: enabled\n",
      "\n",
      "请手动开启NFC\n",
      "请在NFC Tools应用中选择 “其它”-“删除标签”\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "标签删除了吗？删除了就回车继续吧... \n",
      "要启动制作新标签的进程吗？ y/n  y\n",
      "安装一碰传助手？ y/n  n\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "####################################### 一碰传标签二维码生成器 ###############################################\n",
      "随便做的，出错不负责。可以问我，不一定修复\n",
      "\n",
      "cooapk: 花不语笑人痴\n",
      "\tSerialNumbe is  R90MD9NQ      \n",
      "\t    描述. . . . . . . . . . . . . . . : Bluetooth Device (Personal Area Network)\n",
      "\t    物理地址. . . . . . . . . . . . . : 00-C2-C6-B3-24-DB\n",
      "一碰传助手来自https://github.com/webviewisbad/-apk ，请大家有空帮大佬点小星星\n",
      "访问  https://hind.moqiqin.workers.dev/share/PC_Manager/标签制作/  获取一碰传助手.apk。（复制url请务必把结尾的 “/”一起复制，否则无法访问）\n",
      "运行结束，获得的代码为:\n",
      " SN=R90MD9NQ|MAC=00C2C6B324DB|MODELID=00000506 \n",
      "二维码保存路径：  C:\\Users\\moqiq\\Downloads\\tmp\\aaa\\test.png\n",
      "####################################### 一碰传标签二维码生成器 ###############################################\n",
      "\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "搞完了就回车... \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "已连接 HJS5T19425004323\tdevice\n",
      "Package com.huawei.android.instantshare new state: enabled\n",
      "\n",
      "Package com.huawei.pcassistant new state: enabled\n",
      "\n",
      "Package com.huawei.iconnect new state: enabled\n",
      "\n",
      "Package com.huawei.android.internal.app new state: enabled\n",
      "\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "重启完成,回车... \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "已连接 HJS5T19425004323\tdevice\n",
      "Package com.huawei.android.instantshare new state: enabled\n",
      "\n",
      "Package com.huawei.pcassistant new state: enabled\n",
      "\n",
      "Package com.huawei.iconnect new state: enabled\n",
      "\n",
      "Package com.huawei.android.internal.app new state: enabled\n",
      "\n",
      "自己打开NFC\n",
      "如果你使用本程序成功了，而且体验良好，可以考虑给我打赏一杯矿泉水吗？\n",
      "打赏不意味着你可以向我购买什么或者获得什么特权，而且用来表达你成功后的喜悦心情\n",
      "二维码 https://moqiqin.cn/wp-content/uploads/2020/04/dashang.png\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "退出？ y/n  y\n"
     ]
    }
   ],
   "source": [
    "s = 'a'\n",
    "while s != 'y':\n",
    "    system('cls')\n",
    "    main_menu()\n",
    "    \n",
    "    print('如果你使用本程序成功了，而且体验良好，可以考虑给我打赏一杯矿泉水吗？\\n打赏不意味着你可以向我购买什么或者获得什么特权，而且用来表达你成功后的喜悦心情')\n",
    "    print('二维码 https://moqiqin.cn/wp-content/uploads/2020/04/dashang.png')\n",
    "    s = input('退出？ y/n ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
